'''
会议管理UI测试
'''
import unittest
from Lib.base.page_object.meeting_manager.meeting_add import MeetingAdd
from Lib.base.page_object.meeting_manager.meeting_list import MeetingList
from selenium.webdriver.common.by import By
import allure
import os
from Lib.common.assert_class import AssertClass
import pytest


@pytest.fixture(scope='class', autouse=True)
@pytest.mark.usefixtures('login')
def set_cls(login):
    TestMeetingTest.meetingAdd = MeetingAdd(login)
    TestMeetingTest.meetingList = MeetingList(login)
    TestMeetingTest.assert_class = AssertClass(login)


@allure.feature('会议管理页面测试')
class TestMeetingTest:

    @allure.title('新增会议草稿和会议')
    def test_01_meeting_add(self):
        '''
        新增会议草稿和会议详情
        :return:
        '''
        self.meetingAdd.add_meeting()
        assert_data = (By.XPATH, '//p[text()="编辑成功"]')
        self.assert_class.make_assert_by_text(args=assert_data, assert_data='编辑成功', context='新增会议')

    @allure.title('会议列表进行筛选')
    def test_02_meeting_list(self):
        '''
        对会议列表进行筛选
        :return:
        '''
        self.meetingList.list_screen()
        assert_data = (By.XPATH, '//tbody//div[text()="申请人kb"]')
        self.assert_class.make_assert_by_elements_text(args=assert_data, assert_data='申请人kb', context='查询列表')

    @allure.title('查看会议详情和修改会议')
    def test_03_meeting_detail_update(self):
        '''
        查看会议详情和修改会议
        :return:
        '''
        self.meetingList.look_detail_update()
        assert_data = (By.XPATH, '//p[text()="编辑成功"]')
        self.assert_class.make_assert_by_text(args=assert_data, assert_data='编辑成功', context='编辑和查看详情')

    @allure.title('取消会议通知')
    def test_04_meeting_cancel(self):
        '''
        取消会议通知
        :return:
        '''
        self.meetingList.cancel_meeting()
        assert_args = (By.XPATH, '//p[contains(text(), "取消成功")]')
        self.assert_class.make_assert_by_text(args=assert_args, assert_data='取消成功！', context='取消会议通知')


if __name__ == '__main__':
    pytest.main(['-v', '-s', './meeting_test.py'])

